package com.itheima.web.mapper.ums;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.vo.ums.AdminRole;
import com.itheima.vo.ums.UmsAdmin;
import com.itheima.vo.ums.UmsMenu;
import com.itheima.vo.ums.UmsRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AdminMapper extends BaseMapper<UmsAdmin> {
    @Select("select * from ums_admin_role_relation where admin_id = #{id}")
    List<Integer> getRoleIds(Integer id);

    @Select("SELECT * FROM `ums_role_menu_relation` WHERE role_id IN (5) GROUP BY menu_id;")
    List<Integer> getMenuIds(List<Integer> roleId);

    @Select("select r.* from ums_admin_role_relation ar left join ums_role r on ar.role_id = r.id where ar.admin_id = #{id}")
    List<UmsRole> getRoles(Integer id);

    @Select("select m.* from ums_admin_role_relation arr left join ums_role r on arr.role_id = r.id left join ums_role_menu_relation rmr on r.id = rmr.role_id left join ums_menu m on rmr.menu_id = m.id  where  arr.admin_id = #{id} group by m.id;")
    List<UmsMenu> getMenus(Integer id);

    @Select("insert into ums_admin_role_relation values (#{adminId},#{roleId})")
    void saveRole(AdminRole adminRole);
}
